package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.SupplierDao;
import com.atguigu.jxc.entity.Supplier;
import com.atguigu.jxc.service.SupplierService;
import com.atguigu.jxc.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    SupplierDao supplierDao;


    @Override
    public void delete(String ids) {
        String[] split = ids.split(",");
        supplierDao.delete(split);
    }

    @Override
    public void saveOrUpdate(Integer supplierId, Supplier supplier) {
        if(supplierId!=null){
            supplierDao.update(supplier);
        }else {
            supplierDao.save(supplier);
        }
    }

    @Override
    public Map<String, Object> findPage(Integer page, Integer rows, String supplierName) {
        Integer size=(page-1)*rows;
        List<Supplier> list= supplierDao.findPage(size,rows,supplierName);
        Map<String ,Object> map=new HashMap<>();
        map.put("rows",list);
        Integer total=supplierDao.getTotal(supplierName);
        map.put("total",total);
        return map;
    }
}
